<?php
namespace app\common\service;
use app\common\model\Activity as ActivityModel;

class Activity
{
	public function save($data, $id = null)
	{
		if(!empty($data['cover_pic'])) //处理图片上传
		{
			$file = $data['cover_pic'];
			$info = $file->validate(['size'=>200000,'ext'=>'jpg,png,jpeg'])->move('./static/uploads');
			if(!$info)
			{
				return ['status' => false, 'msg' => $file->getError()];
			}
			$data['cover'] = $info->getSaveName();
		}

		if($id)
		{
			$row = ActivityModel::getOrFail($id);
			$row->save($data);
			return ['status' => true];
		}
		ActivityModel::create($data);
		return ['status' => true];
	}
}